package April.fifteen.a;

import java.util.Random;
import java.util.Scanner;

/*
随机生成数组长度为20 查找指定元素是否在数组中
 */
public class Paxu {
    public static void main(String[] args) {
        int jie = -1;
        int[] in = new int[20];
        Random ran = new Random(200);
        for (int i = 0; i <20 ; i++) {
            int a = ran.nextInt(100);
            in[i] = a;
        }
        System.out.println("随机数组为");
        for (int k = 0; k <in.length ; k++) {
            System.out.println(in[k]);
        }

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要查询的数");
        int a2 = sc.nextInt();
        for (int j = 0; j <20 ; j++) {
            if (a2 == in[j]) {
                jie = j;
                break;
            }
        }
        if (jie == -1) {
            System.out.println("没有找到结果");
        }else {
            System.out.println("元素"+a2+"在集合的"+(jie+1)+"位置");
        }
    }

}
